package com.common.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.POST;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.common.dao.DictionaryDAO;
import com.common.dto.DictionaryDTO;
import com.common.exception.LogicException;
import com.common.service.DictionaryService;
import com.common.service.base.BaseService;
import com.common.util.ConstantDefine;

@Service("dictionaryService")
public class DictionaryServiceImpl  extends BaseService<DictionaryDTO> implements DictionaryService{
	
	@Autowired
	private DictionaryDAO dictionaryDAO;

	/**
	 * @function 查询资源分类
	 * @param dictionaryDTO #{typeCode} #{parentCode}
	 * @return
	 * @data 2017-9-11
	 * @author zhongpeng
	 */
	@Override
	public Map<String, Object> selectType(DictionaryDTO dictionaryDTO) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<DictionaryDTO> resultList = dictionaryDAO.selectType(dictionaryDTO);
		resultMap.put("resultList", resultList);
		return resultMap;
	}
	
	/**
	 * @function 分页条件查询  根据类型编号  
	 * @param dictionaryDTO
	 * @return
	 * @data 2017-8-14
	 * @author zhongpeng
	 */
	@Override
	public Map<String, Object> getDictItemPaging(DictionaryDTO dictionaryDTO) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<DictionaryDTO> resultList = dictionaryDAO.getDictItemPaging(dictionaryDTO);
		resultMap.put(ConstantDefine.ROWS, resultList);
		return resultMap;
	}
	

	@POST
    //数据返回类型
	@Override
	public List<DictionaryDTO> select(DictionaryDTO dto) {
		return dictionaryDAO.select(dto);
	}

	@POST
    //数据返回类型
	@Override
	public List<DictionaryDTO> getDictByi(DictionaryDTO item) {
		List<DictionaryDTO> list = dictionaryDAO.getDictByi(item);
		return list;
	}


	@POST
    //数据返回类型
	@Override
	public List<DictionaryDTO> getDictByp(DictionaryDTO parent) {
		return dictionaryDAO.getDictByp(parent);
	}

	/**
	 *根据城市名查找省市编号 
	 */
	@Override
	public Map<String, String> selectItemCodeByItemName(String itemName) {
		return dictionaryDAO.selectItemCodeByItemName(itemName);
	}

	@Override
	public Map<String, Object> check(DictionaryDTO entity) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> checkUpdate(DictionaryDTO entity) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 联动查询，查询出省市区
	 * @author chenby
	 * @date 2017-9-5
	 * @function 
	 */
	@Override
	public List<DictionaryDTO> getPCC(DictionaryDTO entity) {
		
		return dictionaryDAO.getPCC(entity);
	}

	/**根据id删除
	 * @author chenby
	 * @date 2017-10-30
	 * @function 
	 */
	@Override
	public Map<String, Object> deleteById(DictionaryDTO entity) {
		Map<String, Object> resultMap=new HashMap<>();
		//重新排序
		int counts=dictionaryDAO.updateReportD(entity);
		//删除
		int count=dictionaryDAO.deleteByPrimaryKey(entity.getId());
		if(count>0){
			resultMap.put(ConstantDefine.FLAG, ConstantDefine.SUCCESS_MSG);
		}else {
			resultMap.put(ConstantDefine.FLAG, ConstantDefine.FAIL_MSG);
			throw new LogicException("删除报表基础数据失败！");
		}
		return resultMap;
	}

	@Override
	public List<Map> querybyCodes(List<String> areas) {
		List<Map> list = dictionaryDAO.querybyCodes(areas);
		return list;
	}


}
